package org.example.utils;

import cn.hutool.core.util.StrUtil;
import cn.hutool.setting.dialect.Props;
import io.netty.util.internal.StringUtil;

public class ConfigUtils {
    /**
     * 加载配置
     * @param clazz
     * @param prefix
     * @return
     * @param <T>
     */
    public static <T> T loadConfig(Class<T> clazz,String prefix){
        return loadConfig(clazz,prefix,"");
    }

    /**
     * 加载配置
     * @param clazz
     * @param prefix
     * @param environment
     * @return
     * @param <T>
     */
    public static <T> T loadConfig(Class<T> clazz,String prefix,String environment) {
        StringBuilder application = new StringBuilder("application");
        if (StrUtil.isNotBlank(environment)){
            application.append("-").append(environment);
        }
        StringBuilder append = application.append(".properties");
        Props props = new Props(append.toString());
        return props.toBean(clazz,prefix);
    }
}
